package top.kaoshanji.p2ch15b;

/**
 * 代码清单-p2ch15b-457页b：使用MyLatch的工作子线程
 * author kaoshanji
 * ^_^
 * create time 2025/2/24 17:24
 */
public class MyLatchWorkerThread extends Thread {

    private MyLatch latch;

    public MyLatchWorkerThread(MyLatch latch) {
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            // simulate working on task
            Thread.sleep((int) (Math.random() * 1000));
            System.out.println("线程："+Thread.currentThread().getName()+"完成了，线程总量就减1...");

            this.latch.countDown();
        } catch (InterruptedException e) {
            /// ////
        }
    }
}
